<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of QueryDao
 *
 * @author lzx
 */
require_once BaseUtil::getModulePath('base').'/models/BaseDao.php';

class QueryDao extends BaseDao{
	
    //put your code here
    protected $_name;
    
    public function _setup(){
        $this->_name = $this->prefix().'queries';
        parent::_setup();
    }
    
    public function updateQuery($data,$id){
         $where = $this->db_w->quoteInto('id = ?', $id);
         $this->updateData($data,$where);
    }
    
    public function deleteQuery($id){
    	$isDel = array("is_delete"=>1);
    	$where =  $this->db_w->quoteInto('id = ?', $id);
    	$this->updateData($isDel, $where);
    }
    
    public function getQuery($queryId){
        $select = $this->db_r->select();
        $select->from($this->_name,array('id','query_type','status','evaluate_value','evaluate_time','content','created'));        
//        $select->join('product_items', 'product_items.id=queries.product_item_id','upc');
//        $select->join('product_items', 'product_items.product_id=queries.product_id','product_id');
        
        $select->joinLeft('products','products.id=queries.product_id',array("id","title"));
        $select->joinLeft('users', 'users.id=queries.customer_id','name');
        $select->where('queries.id=?',$queryId);
        $select->where('queries.is_delete=?',0);
        $sql = $select->__toString();
        $result = $this->db_r->fetchAll($sql);
        return $result[0];
    }
    
    
}
?>